<?php


function mapping_usr_name_to_portfolio_access_id($usr_name) {
	elgg_load_library('elgg:oci_access');	
	
	$recordset = oci_query("select user_id from user_mapping where user_name='$usr_name'");
	if(is_array($recordset) && count($recordset) > 0) {
		return $recordset[0][0];
	}
	
	return 'anonymous';
}

function get_param_value($param_key, $session_key, $default_val)
{
	$val = get_input($param_key);
	if (!$val) {
		if (strpos($_SERVER['QUERY_STRING'], $param_key)) { //have no querystring
		} else if ($_SESSION[$session_key]) {
			$val = $_SESSION[$session_key];
		} else if (!isset($_SESSION[$session_key])) {
			$val = $default_val;
		} else {
		}
	}
	
	return $val;
}

function json_array_encode($arr, &$output) {
	if($arr && is_array($arr)) {
		$output .= '[';
		
		$n = 0;		
		foreach($arr as $elem) {
			
			if($n++ > 0) 
				$output .= ',';
			
			if(is_array($elem)) {
				json_array_encode($elem, $output);
			} else {
				$output .= $elem;
			}
		}		
		$output .= ']';
	}		
	
	return;
}

function concat_array_to_string($array_val, $delimiter = ',') {
	$str_val = '';
	
	if(is_array($array_val) && count($array_val) > 0) {
		$num = 0;
		foreach($array_val as $elem) {
			if($num++ > 0)
				$str_val .= $delimiter;
				
			$str_val .= $elem;
		}
	}
	
	return $str_val;
}